const http = require('http');
const resolveUrl = require('url');
const path = require('path')
const PORT = 9999;

const server = http.createServer((req, res) => {

  // 1. 读文件
  // 后缀  .html  .js  .css
  const url = req.url;
  const pathname = resolveUrl.parse(url).pathname;
  const extname = path.extname(pathname);
  res.writeHead(200, {
    'Content-type': "text/html;charset=utf-8"
  })

  if (extname) {
    if (extname === '.ico') {
      res.end('111')
      return;
    }
    console.log(extname, 'extnamme')
    res.end('页面')
    return;
  } else {
    // 2. 写接口
    // api/login  api/register
    res.end('接口')
    return;
  }
})

server.listen(PORT, () => {
  console.log(`server port is ${PORT}`)
})